package com.ly.web.controller.erp;

import com.ly.common.core.domain.AjaxResult;
import com.ly.heart.domain.FileEntity;
import com.ly.heart.service.IFileInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

@Api (value = "FileEntity", tags = "附件表")
@RestController
@RequestMapping ("/heart/file")
public class FileInfoController {

    @Resource
    private IFileInfoService fileInfoService;

    @PostMapping ("/fileUpload")
    @ApiOperation ("上传附件")
    public AjaxResult customerUpload (@RequestParam ("files") MultipartFile[] files, @RequestParam ("type") Integer type) {
        List<FileEntity> fileEntities = fileInfoService.uploadFiles ( files, type );
        return AjaxResult.success ( fileEntities );
    }

    /**
     * 单个文件上传，不入库，将对象全部返回，前端带回到业务对象，业务对象中再行保存
     * @param file
     * @param type
     * @return
     */
    @PostMapping ("/upload")
    @ApiOperation ("上传单个附件")
    public AjaxResult upload (@RequestParam ("file") MultipartFile file, @RequestParam ("type") Integer type) {
        FileEntity fileEntity = fileInfoService.uploadFile ( file, type );
        return AjaxResult.success ( fileEntity );
    }
}
